package cn.sjx.graduate.web.controller;

import cn.sjx.graduate.domain.Department;
import cn.sjx.graduate.qo.QueryObject;
import cn.sjx.graduate.service.IDepartmentService;
import cn.sjx.graduate.util.JsonResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bo-feifei
 * @since 2021-11-07
 */
@RestController
@RequestMapping("/department")
@Api(tags = "部门相关信息接口")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;


    @GetMapping("query")
    @ApiOperation(value = "分页查询所有部门信息")
    public JsonResult<IPage<Department>> query(QueryObject qo) {
        return JsonResult.success(departmentService.queryPage(qo));
    }

    @ResponseBody
    @PostMapping("/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody Department department) {
        if (department == null) {
            return JsonResult.error("参数不能为空");
        }
        boolean b = departmentService.saveOrUpdate(department);
        return JsonResult.success(b);
    }

    @ResponseBody
    @DeleteMapping("/delete")
    public JsonResult<?> delete(@RequestParam Integer id) {
        if (null == id) {
            return JsonResult.error("删除的部门id不能为空");
        }
        departmentService.removeById(id);
        return JsonResult.success("删除成功");
    }


}

